added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / tools / genpalunitable / genpalunitable.cpp
blob9d7c77498e3e1e8cb320b20c71a6df3e03fd5948
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 // This tool generates the unicode_data.c file which contains the unicode data table
18 #include <ctype.h>
19 #include <stdio.h>
20 #include <windows.h>
22 CONST char copyright_header[] =
23 "// ==++==\n"
24 "// \n"
25 "// Copyright (c) Microsoft Corporation. All rights reserved.\n"
26 "// \n"
27 "// ==--==\n"
28 "\n"
29 "// This file is generated by rotor/tools/genpalunitable.\n"
30 "\n"
31 "#include \"pal/unicode_data.h\"\n"
32 "\n"
33 "CONST UnicodeDataRec UnicodeData[] =\n"
34 "{\n";
36 /* If we need the description of unicode chars in unicode_data.c, then we just
37 have to set UnicodeDataStrings table with all wchars description strings */
38 char* UnicodeDataStrings[] = {""};
40 int __cdecl main(int argc, char *argv[])
42 FILE *fpOut;
43 WORD Info,
44 InfoOut = 0xFFFF,
45 duplicate = 0,
47 iOut = 0xFFFF;
49 WCHAR oppC = 0,
50 oppCout = 0xFFFF;
51 CONST UINT LAST_DIRECT_ACCESS = 256;
53 if (!(fpOut = fopen("unicode_data.c", "w")))
55 printf("Unable to open unicode_data.c for write\n");
56 return 1;
59 fprintf(fpOut, "%s", copyright_header);
61 for (i=0; i < 0xFFFF; i++)
63 if (!GetStringTypeExW(LOCALE_USER_DEFAULT, CT_CTYPE1,
64 (WCHAR*)&i, 1, &Info))
66 fprintf(fpOut,
67 "GetStringTypeExW failed to get information for %#X!\n", i);
68 return 1;
71 oppC = iswupper(i) ? towlower(i) : (iswlower(i) ? towupper(i) : 0);
73 /* Print out all 256 first chars */
74 if (i <= LAST_DIRECT_ACCESS)
76 fprintf(fpOut, "{ 0x%04x,\t0x%04x,\t0x%04x,\t%d },\t\t%s\n",
77 i, Info, oppC, 0, UnicodeDataStrings[/*i*/0]);
79 else
81 if ((oppC != 0) || (Info != 0))
83 /* We don't need to print out all chars with the same C1_TYPE
84 and with the same opposite char */
85 if ((oppC == oppCout) && (Info == InfoOut))
87 duplicate ++;
88 fprintf(fpOut, "/*0x%04x,\t0x%04x,\t0x%04x,\t%d } */\t\t%s\n",
89 i, Info, oppC, 0, UnicodeDataStrings[/*i*/ 0]);
92 else
94 if (iOut != 0xFFFF)
96 fprintf(fpOut, "{ 0x%04x,\t0x%04x,\t0x%04x,\t%d },"
97 "\t\t%s\n", iOut, InfoOut, oppCout, duplicate,
98 UnicodeDataStrings[/*iOut*/ 0]);
101 /* reset the next char to print out */
102 InfoOut = Info;
103 oppCout = oppC;
104 duplicate = 0;
105 iOut = i;
108 else
110 fprintf(fpOut, "/*0x%04x,\t0x%04x,\t0x%04x,\t%d } */\t\t%s\n",
111 i, Info, oppC, 0, UnicodeDataStrings[/*i*/0]);
117 fprintf(fpOut, "};\n\n");
118 fprintf(fpOut, "CONST UINT UNICODE_DATA_SIZE = "
119 "sizeof(UnicodeData)/sizeof(UnicodeDataRec);\n");
120 fprintf(fpOut, "CONST UINT UNICODE_DATA_DIRECT_ACCESS = %d;\n",
121 LAST_DIRECT_ACCESS);
123 fclose(fpOut);
125 return 0;